//
//  ImageScrollView.m
//  UIScrollView-山水图
//
//  Created by student on 16/2/29.
//  Copyright © 2016年 niit. All rights reserved.
//

#import "ImageScrollView.h"

@interface ImageScrollView ()<UIScrollViewDelegate>

@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) IBOutlet UIPageControl *pageControl;

@end

@implementation ImageScrollView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/
-(void)setImageNames:(NSArray *)imageNames{
    _imageNames=imageNames;
    
    //设定scrollView
    CGFloat imgWidth=self.scrollView.bounds.size.width;
    CGFloat imgHeight=self.scrollView.bounds.size.height;
    for (int i=0; i<imageNames.count; i++) {
        UIImageView *imageView=[[UIImageView alloc]initWithFrame:CGRectMake(imgWidth*i, 0, imgWidth, imgHeight)];
        imageView.image=[UIImage imageNamed:imageNames[i]];
        [self.scrollView addSubview:imageView];
    }
    self.scrollView.contentSize=CGSizeMake(imgWidth*self.imageNames.count, 0);
    
    self.pageControl.numberOfPages=imageNames.count;
}

-(void)setOtherColor:(UIColor *)otherColor{
    _otherColor=otherColor;
    self.pageControl.pageIndicatorTintColor=otherColor;
}

-(void)setCurColor:(UIColor *)curColor{
    _curColor=curColor;
    self.pageControl.currentPageIndicatorTintColor=curColor;
}

//第一步：创建对象
//方式1：在initWithFrame中创建对象
//方式2：用懒加载
-(id)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if (self) {
       //创建scrollView
        UIScrollView *scrollView=[[UIScrollView alloc]init];
        [self addSubview:scrollView];
        
        scrollView.pagingEnabled=YES;
        scrollView.showsHorizontalScrollIndicator=NO;
        self.scrollView=scrollView;
        
        self.scrollView.delegate=self;
        //创建pageControl
        UIPageControl *pageControl=[[UIPageControl alloc]init];
    }
    return self;
}















@end
